/**
 * 安全工具类
 * User: zhaoming
 * Date: 15-8-18
 * Time: 上午11:47
 * To change this template use File | Settings | File Templates.
 */
var securityUtils = {};

/**
 * AES加密
 * @param text 文本
 * @returns {string} 加密文本
 */
securityUtils.aesEncrypt = function(text, key){
    var srcs = CryptoJS.enc.Utf8.parse(text);
    var encrypted = CryptoJS.AES.encrypt(srcs, CryptoJS.enc.Utf8.parse(key), {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
    return encrypted.toString();
};

/**
 * AES解密
 * @param text 加密文本
 * @returns {string} 文本
 */
securityUtils.aesDecrypt = function(text, key){
    var decrypt = CryptoJS.AES.decrypt(text, CryptoJS.enc.Utf8.parse(key), {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
    return CryptoJS.enc.Utf8.stringify(decrypt).toString();
};

/**
 * 加密Key
 */
securityUtils.getKey = function(){
    var key = "";
    jQuery.ajax({
        type: "POST",
        dataType: "json",
        async: false,
        url: springUrl+"/security/getKey",
        success: function (data) {
            key = data.key;
        }
    });
    return key;
};